package com.example.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

@Service
public class DbConnectionService {
	private static final Logger logger = LoggerFactory.getLogger(DbConnectionService.class);
	
	public void testConnection(String jdbcUrl, String username, String password) throws SQLException {
		logger.info("尝试连接数据库: {}", jdbcUrl);
		logger.debug("使用用户名: {}", username);
		
		try (Connection ignored = DriverManager.getConnection(jdbcUrl, username, password)) {
			logger.info("数据库连接成功");
		} catch (SQLException e) {
			logger.error("数据库连接失败: {}", e.getMessage(), e);
			throw e;
		}
	}
} 